//
//  StatusCell.swift
//  VVbo
//
//  Created by Mr.Run on 2017/8/28.
//  Copyright © 2017年 Mr.Run. All rights reserved.
//

import UIKit

protocol StatusCellDelegate: NSObjectProtocol {
    
    func statusCellDidSelectedLinkStr(cell: StatusCell, urlString: String)
    
}

class StatusCell: UITableViewCell {
    
    weak var delegate: StatusCellDelegate?
    
    var viewModel: StatusViewModel? {

        didSet{
            
            statusLabel.attributedText = viewModel?.statusAttrText
            retweetedLabel?.attributedText = viewModel?.retweetedAttrText
            nameLabel.text = viewModel?.status.user?.screen_name
            memberIconView.image = viewModel?.memberIcon
            vipIconView.image = viewModel?.vipIcon
            iconView.vv_setImage(urlString: viewModel?.status.user?.profile_image_url, placeholderImage: UIImage(named: "avatar_default_big"), isAvatar: true)
            toolBar.viewModel = viewModel
            pictureView.viewModel = viewModel
//            pictureView.heightCons.constant = viewModel?.pictureViewSize.height ?? 0
//            pictureView.urls = viewModel?.picURLs
            sourceLabel.text = viewModel?.status.source
        }
    }
    
    
    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var nameLabel: UILabel!
    
    @IBOutlet weak var memberIconView: UIImageView!
    
    @IBOutlet weak var timeLabel: UILabel!
    
    @IBOutlet weak var sourceLabel: UILabel!
    
    @IBOutlet weak var statusLabel: FFLabel!
    
    @IBOutlet weak var vipIconView: UIImageView!
    
    @IBOutlet weak var toolBar: StatusToolBar!
    
    @IBOutlet weak var pictureView: StatusPictureView!
    
    @IBOutlet weak var retweetedLabel: FFLabel?
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.layer.drawsAsynchronously = true
        self.layer.shouldRasterize = true
        self.layer.rasterizationScale = UIScreen.main.scale
        statusLabel.delegate = self
        retweetedLabel?.delegate = self
    }
}

extension StatusCell: FFLabelDelegate {
    
    func labelDidSelectedLinkText(label: FFLabel, text: String) {
        if !text.hasPrefix("http://"){
            return
        }
        
        delegate?.statusCellDidSelectedLinkStr(cell: self, urlString: text)
        
    }
    
}
